from abc import ABCMeta, abstractmethod

from flask import current_app as app


class BaseHandler(metaclass=ABCMeta):
    def __init__(self, task):
        self.task = task
        self.target = task.target
        self.task_type = task.taskType
        self.task_settings = task.taskSettings.to_dict()
        self.response = task.result.addition
        self._check_response()

    @abstractmethod
    def handle(self, **kwargs):
        pass

    def _check_response(self):
        if not self.response:
            app.logger.exception(f'[02]监测结果处理：task {self.task.id}任务结果为空')
